Arithmetic operators are used with numeric values to perform common mathematical operations:
⯄
Addition (+): This operator adds two operands. For example, x + y would add the values of x and y.
⯄
Subtraction (-): This operator subtracts the right operand from the left operand. For example, x - y would subtract the value of y from x.
⯄
Multiplication (*): This operator multiplies two operands. For example, x * y would multiply the values of x and y.
⯄
Division (/): This operator divides the left operand by the right operand. For example, x / y would divide x by y.
⯄
Modulus (%): This operator returns the remainder when the left operand is divided by the right operand. For example, x % y would return the remainder of x divided by y.
⯄
Exponentiation (**): This operator raises the left operand to the power of the right operand. For example, x ** y would raise x to the power of y.
⯄
Floor Division (//): This operator divides the left operand by the right operand and rounds down to the nearest whole number. For example, x // y would divide x by y and round down to the nearest whole number.
Here’s an example of these operators in use:
Example of Arithmetic operator in python
x = 10
y = 3
print("x + y =", x + y) # Addition
print("x - y =", x - y) # Subtraction
print("x * y =", x * y) # Multiplication
print("x / y =", x / y) # Division
print("x % y =", x % y) # Modulus
print("x ** y =", x ** y) # Exponentiation
print("x // y =", x // y) # Floor division
Output
x + y = 13
x - y = 7
x * y = 30
x / y = 3.3333333333333335
x % y = 1
x ** y = 1000
x // y = 3